Interface('Traceable',
uncloned:[
	'createTimestamp',
	'lastUpdateTimestamp'
],
interceptors:'TraceableLifecycleInterceptor') {
	date_time 'createTimestamp', readOnly:true, timeZoneAware:true
	date_time 'lastUpdateTimestamp', readOnly:true, timeZoneAware:true
}

Entity ('User', icon:'person.png', extend:'Traceable', extension:'UserExtension', toString:'fullName',
rendered:[
		'firstName',
		'lastName',
		'position',
		'email',
		'mobile',
		'birth_date',
		'login'
	],
interceptors:'UserLifecycleInterceptor') {
	string_64 'firstName', mandatory:true
	string_64 'lastName', mandatory:true
	enumeration 'position', enumName:'USER_FUNCTION', mandatory:true,
	values: [
		'PROF',
		'POS_DOC',
		'DOC',
		'MASTER',
		'STUDENT_CI',
		'STUDENT_VOL',
		'TECNICIAN',
		'SCIENTIST'
	]
	string_32  'login', mandatory:true, unicityScope:'scope_login'
	password 'password', mandatory:true
	enumeration 'language', enumName:'language', values:['pt', 'en', 'de']
	set 'roles', ref:'Role', reverse:'Role-users'
	string 'fullName', readOnly:true, computed:true
	string_32 'mobile'
	date 'birth_date'
	string_256 'email', mandatory:true, regex:"[\\w\\-\\.]*@[\\w\\-\\.]*", regexSample:'ze.das.coisas@geologia.ufrn.br'
}

Entity ('Role') {
	string_16 'roleId', mandatory:true, unicityScope:'roleId'
	set 'users', ref:'User', composition:false, reverse:'User-roles'
}

Entity('Equipments', icon:'equipments.png', extend:'Traceable') {
	string_64 'referenceNumber', mandatory:true
	string_64 'name', mandatory:true
	string_64 'model', mandatory:true
	string_64 'manufacturer'
	text 'details', maxLength:2048
	enumeration 'type', enumName:'CAPITAL_GOOD_TYPE', mandatory:true,
	values: [
		'COMPUTER',
		'HARDWARE',
		'LAB_EQUIPMENT',
		'FIELD_EQUIP',
		'OTHERS'
	]
	set 'maintenances', ref:'Maintenance', composition:true, reverse:'Maintenance-equipment'
	set 'lendings', ref:'Lending', reverse:'Lending-equipments'
}

Entity ('Lending', icon:'lending.png', extend:'Traceable') {
	string_64 'referenceNumber', mandatory:true
	string_256 'contact_name', mandatory:true
	string_256 'contact_email', regex:"[\\w\\-\\.]*@[\\w\\-\\.]*", regexSample:'ze.das.coisas@geologia.ufrn.br'
	string_32 'contact_phone'
	text 'contact_address', maxLength:1024
	text 'additional_info', maxLength:2048
	date 'scheduled_date_out'
	date 'scheduled_date_in'
	date 'outgoing_date'
	date 'incoming_date'
	bool 'tested_on_lending'
	bool 'tested_on_return'
	text 'test_remarks', maxLength:2048
	reference 'executed_by', ref:'User', rendered:[
		'firstName',
		'lastName',
		'position'
	]
	set 'equipments', ref:'Equipments'
}

Entity ('Maintenance', icon:'maintenance.png', extension:'MaintenanceExtension', extend:'Traceable') {
	string_256 'name', mandatory:true
	text 'description', maxLength:2048
	integer 'interval_in_days'
	bool 'active'
	date 'last_execution', readOnly:true, computed:true, computedFurther:true
	integer 'days_left', readOnly:true, computed:true, computedFurther:true
	reference 'equipment', ref:'Equipments'
	set 'executions', ref:'MaintenanceExecution', composition:true, reverse:'MaintenanceExecution-maintenance'
}

Entity ('MaintenanceExecution', extend:'Traceable') {
	date 'maintenance_date', mandatory:true
	text 'additional_info', maxLength:2048
	bool 'passed'
	reference 'executed_by', ref:'User', rendered:[
		'firstName',
		'lastName',
		'position'
	], mandatory:true
	reference 'maintenance', ref:'Maintenance', readOnly:true
}

Entity('ConsumerGoods', icon:'consumer_goods.png', extension:'ConsumerGoodsExtension', extend:'Traceable') {
	string_64 'referenceNumber', mandatory:true
	string_64 'name', mandatory:true
	string_64 'model', mandatory:true
	string_64 'manufacturer'
	text 'details' , maxLength:2048
	enumeration 'type', enumName:'CONSUMER_GOOD_TYPE', mandatory:true, values: [
		'LAB_CHEMICAL',
		'OFFICE',
		'LAB_ACCESSORY',
		'OTHERS'
	]
	integer 'min_inventory', defaultValue:0
	integer 'current_inventory', readOnly:true, computed:true, computedFurther:true
	set 'inventory_changes', ref:'InventoryChange', composition:true, reverse:'InventoryChange-consumerGoods'
}

Entity ('InventoryChange', icon:'transfer.png', extend:'Traceable') {
	integer 'quantity', mandatory:true
	enumeration 'type', enumName:'INVENTORY_CHANGE_TYPE', values: ['INCOMING', 'OUTGOING'], mandatory:true
	reference 'executed_by', ref:'User', rendered:[
		'firstName',
		'lastName',
		'position'
	], mandatory:true
	text 'additional_info', maxLength:512
	reference 'consumerGoods', ref:'ConsumerGoods', readOnly:true
}

